package com.example.shiyan2;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.appcompat.app.AppCompatActivity;

public class Activity1 extends AppCompatActivity {
    private LinearLayout Container;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_1);

        // 返回按钮点击监听器
        Button backButton = findViewById(R.id.returnButton);
        backButton.setOnClickListener(v -> finish());

        // 获取LinearLayout引用
        Container = findViewById(R.id.container);

        // 水平布局按钮点击监听器
        Button horizontalButton = findViewById(R.id.horizontalButton);
        horizontalButton.setOnClickListener(v -> horizontalSort());

        // 垂直布局按钮点击监听器
        Button verticalButton = findViewById(R.id.verticalButton);
        verticalButton.setOnClickListener(v -> verticalSort());

        // 靠左布局按钮点击监听器
        Button leftButton = findViewById(R.id.leftButton);
        leftButton.setOnClickListener(v -> leftAlign());
    }

    // 设置LinearLayout为水平方向
    private void horizontalSort() {
        Container.setOrientation(LinearLayout.HORIZONTAL);
    }

    // 设置LinearLayout为垂直方向
    private void verticalSort() {
        Container.setOrientation(LinearLayout.VERTICAL);
    }

    // 设置子View左对齐
    @SuppressLint("RtlHardcoded")
    private void leftAlign() {
        Container.setGravity(Gravity.START);
    }
}